package forms;

import org.apache.struts.action.*;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class StudentsForm extends ActionForm {

	private static final long serialVersionUID = 1L;
	
	// Variables that make a student
	private String firstName = null;
	private String miName = null;
	private String lastName = null;
	
	private String citizenship = null;
	
	private String residency = null;
	
	private String address = null;
	private String city = null;
	private String state = null;
	private String zipCode = null;
	private String areaCode = null;
	private String countryCode = null;
	private String phone = null;
	
	private String permanent = null;
	
	private String specialization = null;

	// Name getter/setters
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String first) {
		this.firstName = first;
	}
	public String getMiName() {
		return miName;
	}
	public void setMiName(String middle) {
		this.miName = middle;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String last) {
		this.lastName = last;
	}
	
	// Citizenship getter/setter
	public String getCitizenship() {
		return citizenship;
	}
	public void setCitizenship(String c) {
		this.citizenship = c;
	}

	// Residency getter/setter
	public String getResidency() {
		return residency;
	}
	public void setResidency(String r) {
		this.residency = r;
	}
	
	// Address getter/setters
	public String getAddress() {
		return address;
	}
	public void setAddress(String add) {
		this.address = add;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getState() {
		return state;
	}
	public void setState(String s) {
		this.state = s;
	}
	public String getZipCode() {
		return zipCode;
	}
	public void setZipCode(String zip) {
		this.zipCode = zip;
	}
	public String getAreaCode() {
		return areaCode;
	}
	public void setAreaCode(String area) {
		this.areaCode = area;
	}
	public String getCountryCode() {
		return countryCode;
	}
	public void setCountryCode(String country) {
		this.countryCode = country;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String p) {
		this.phone = p;
	}
	
	// Permanent getter/setter
	public String getPermanent() {
		return permanent;
	}
	public void setPermanent(String p) {
		this.permanent = p;
	}
	
	// Specialization getter/setter
	public String getSpecialization() {
		return specialization;
	}
	public void setSpecialization(String s) {
		this.specialization = s;
	}
	
	/*
	// reset
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		setFirstName(null);
		setMiName(null);
		setLastName(null);
		setCitizenship(null);
		setResidency(null);
		setAddress(null);
		setCity(null);
		setState(null);
		setZipCode(null);
		setAreaCode(null);
		setPhone(null);
		setPermanent(null);
		setSpecialization(null);
	}
	*/
	// validate
	/*
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();

		if (firstName == null) {
			errors.add("first", new ActionMessage("error.firstName.required"));
			setFirstName("");
		}
		if (lastName == null) {
			errors.add("last", new ActionMessage("error.lastName.required"));
			setLastName("");
		}
		if (isInvalidName(firstName)) {
			errors.add("first", new ActionMessage("error.firstName.invalid"));
			setFirstName("");
		}
		if (isInvalidName(miName)) {
			errors.add("middle", new ActionMessage("error.miName.invalid"));
			setMiName("");
		}
		if (isInvalidName(lastName)) {
			errors.add("last", new ActionMessage("error.lastName.invalid"));
			setLastName("");
		}
		if (address == null) {
			errors.add("address", new ActionMessage("error.address.required"));
			setAddress("");
		}
		if (city == null) {
			errors.add("city", new ActionMessage("error.city.required"));
			setCity("");
		}
		if (phone == null) {
			errors.add("phone", new ActionMessage("error.phone.required"));
			setPhone("");
		}
		else {
			if (isInvalidPhone(phone)) {
				errors.add("phone", new ActionMessage("error.phone.invalid"));
				setPhone("");
			}
		}

		if (citizenship.equals("United States")) {
			if (state == null) {
				errors.add("state", new ActionMessage("error.state.required"));
				setState("");
			}
			if (areaCode == null) {
				errors.add("areaCode", new ActionMessage("error.areaCode.required"));
				setAreaCode("");
			}
			else {
				if (isInvalidAreaCode(areaCode)) {
					errors.add("areaCode", new ActionMessage("error.areaCode.invalid"));
					setAreaCode("");
				}
			}
			if (zipCode == null) {
				errors.add("zip", new ActionMessage("error.zip.required"));
				setZipCode("");
			}
		}
		
		return errors;
	}
	
	// Validate Names
	private boolean isInvalidName(String name)
	{
		boolean invalid = false;
		
		// Check if names are valid
		invalid = true;
		
		return invalid;
	}
	
	// Validate Address
	private boolean isInvalidPhone(String p) {
		boolean invalid = false;
		
		// Check for invalid phone numbers
		invalid = true;
		
		return invalid;
	}
	private boolean isInvalidAreaCode(String ac)
	{
		boolean invalid = false;
		
		// Check for invalid area codes
		invalid = true;

		return invalid;
	}
	*/
}
